package Server.Jsmj.RGCP;

import org.json.JSONObject;

public class CMD_Maj {

}

class IJsonExport {
	public String toString() {
		return getJsonData();
	}

	private String getJsonData() {
		return "";
	}

	public static String sprintf_BYTE(int by[][], int count) {

		int tmpCardData[] = new int[count]; // �û��˿�
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[][], int count) {

		int tmpCardData[] = new int[count]; // �û��˿�
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_BYTE(int by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_DWORD(int dw[], int count) {
		return sprintf_INT32(dw, count);
	}

	public static String sprintf_INT32(Integer dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}

	public static String sprintf_INT32(int dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
}

/***
 * ���������뷿��
 */
class SUBCMD_S_Connect extends IJsonExport {

	int m_lUid;

	String getJsonData() {
		String cpmsg = String.format("connect|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_Join extends IJsonExport {

	int m_lUid;

	String getJsonData() {

		String cpmsg = String.format("join|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// �뿪����֪ͨ
class SUBCMD_S_Leave extends IJsonExport {

	int m_lUid;// ���ID

	String getJsonData() {

		String cpmsg = String.format("leave|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_CreateRoom extends IJsonExport {

	int cbResult;
	int cbRound;
	short m_wUserChairID;// ��λID
	int m_dwTableID;// ����ID

	String getJsonData() {

		String cpmsg = String.format("createroom|%d|%d|%d|%d", cbResult, cbRound, m_wUserChairID, m_dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_Param extends IJsonExport {

	int m_dwTableID;// ����ID
	String szParam;
	String szRoomDesc;
	String fenxiangStr;
	int m_daikai;
	int m_creater;
	String getJsonData() {

		String cpmsg = String.format("param|%d|%s|%s|%s|%d|%d", m_dwTableID, szParam, szRoomDesc, fenxiangStr,m_daikai,m_creater);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_AllDismissRoom extends IJsonExport {

	int[] is_agree_dismiss;
	long dismissTimer;

	String getJsonData() {
		String is_agree_dismissStr = sprintf_INT32(is_agree_dismiss, RGCPTable.PLAYERCOUNT);
		String cpmsg = String.format("all_dismissroom|%s|%d", is_agree_dismissStr, dismissTimer);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_DismissRoom extends IJsonExport {

	int cbResult;
	long lUid;
	short m_wUserChairID;// ��λID
	int m_dwTableID;// ����ID

	String getJsonData() {

		String cpmsg = String.format("dismissroom|%d|%d|%d|%d", cbResult, lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_JoinRoom extends IJsonExport {

	int lUid;
	int cbResult;
	int dwTableID;// ����ID
	int cbRound;
	String strParam;
	String szGameName;
	String szGameDesc;

	String getJsonData() {

		String cpmsg = String.format("joinroom|%d|%d|%d|%d|%s|%s|%s", lUid, cbResult, dwTableID, cbRound, strParam,
				szGameName, szGameDesc);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// class SUBCMD_S_AvatarURL extends IJsonExport {
//
// long lUid;
// String szURL;
//
// String getJsonData() {
//
// String cpmsg = String.format("avatar|%d|%s", lUid, szURL);
// JSONObject json = new JSONObject();
// json.put("command", "cpmsg");
// json.put("cpmsg", cpmsg);
//
// return json.toString();
// }
// };

class SUBCMD_S_Sit extends IJsonExport {

	int m_lUid;
	int m_wUserChairID;// ��λID
	int m_dwTableID;// ����ID
	int m_lUserScore;
	String szNickName;
	int m_cbGender;
	int m_iAvatar;
	String szIP;

	String getJsonData() {

		String cpmsg = String.format("sit|%d|%d|%d|%d|%s|%d|%d|%s", m_lUid, m_wUserChairID, m_dwTableID, m_lUserScore,
				szNickName, m_cbGender, m_iAvatar, szIP);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_DenySit extends IJsonExport {

	int cbReason; // 1,û���ҵ�����,2����������

	String getJsonData() {

		String cpmsg = String.format("denysit|%d", cbReason);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_Look extends IJsonExport {

	int m_lUid;
	short m_wUserChairID;// ����ID
	int m_iTotalCoin;
	String szNickName;

	String getJsonData() {

		String cpmsg = String.format("look|%d|%d|%d|%d|%s", m_lUid, m_wUserChairID, m_iTotalCoin, szNickName);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_StandUp extends IJsonExport {

	int m_lUid;// ���ID
	int m_wUserChairID;// ��λID
	int m_dwTableID;// ����ID

	String getJsonData() {

		String cpmsg = String.format("standup|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_OffLine extends IJsonExport {

	int m_lUid;// ���ID
	int m_wUserChairID;// ��λID
	int m_dwTableID;// ����ID

	String getJsonData() {

		String cpmsg = String.format("offline|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_StandUp_Success extends IJsonExport {
	int index = 0;

	String getJsonData() {
		String cpmsg = String.format("standup_success|%d", index);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// class SUBCMD_S_Kick extends IJsonExport {
//
// int m_lUid;// ���ID
// short m_wUserChairID;// ��λID
// int m_dwTableID;// ����ID
//
// String getJsonData() {
//
// String cpmsg = String.format("kick|%d|%d|%d", m_lUid, m_wUserChairID,
// m_dwTableID);
// JSONObject json = new JSONObject();
// json.put("command", "cpmsg");
// json.put("cpmsg", cpmsg);
//
// return json.toString();
// }
// };

class SUBCMD_S_Ready extends IJsonExport {

	int m_lUid;// ���ID
	int m_wUserChairID;// �����λ
	int m_dwTableID;// ����ID

	String getJsonData() {

		String cpmsg = String.format("ready|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

/**
 * ����ѡ����ׯ
 * 
 * @author ann
 *
 */
class SUBCMD_S_LAZHUANG extends IJsonExport {
	int is_show;

	int byZhuang;
	int byRound;//
	int byMaxRound;
	int byYuPai;//
	int lazhuang_is_end;// 0:������ׯ�� 1:��ׯ�Ѿ�����

	String getJsonData() {
		String cpmsg = String.format("lazhuang|%d|%d|%d|%d|%d|%d", is_show, byZhuang, byRound, byMaxRound, byYuPai,
				lazhuang_is_end);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
}

/**
 * ������ׯ����
 * 
 * @author ann
 *
 */
class SUBCMD_S_LAZHUANG_Score extends IJsonExport {
	int[] lazhuang_score;

	String getJsonData() {
		String lazhuang_scoreStr = sprintf_INT32(lazhuang_score, 4);
		String cpmsg = String.format("lazhuang_score|%s", lazhuang_scoreStr);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
}
class SUBCMD_S_LiWu extends IJsonExport {

	int m_index;
	int m_fromSeat;
	int m_toSeat;
	
	String getJsonData() {

		String cpmsg = String.format("liwu|%d|%d|%d", m_index, m_fromSeat,m_toSeat);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};
// �������
class SUBCMD_S_BiaoQing extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	int m_wUserChairID;// �����λ
	int m_iBiaoQingIndex;

	String getJsonData() {

		String cpmsg = String.format("biaoqing|%d|%d|%d", m_lUid, m_wUserChairID, m_iBiaoQingIndex);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ����
class SUBCMD_S_YuYin extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	int m_wUserChairID;// �����λ��
	int m_iYuYinIndex;

	String getJsonData() {

		String cpmsg = String.format("yuyin|%d|%d|%d", m_lUid, m_wUserChairID, m_iYuYinIndex);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ����
class SUBCMD_S_Avatar extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	String szAvatarURL;

	String getJsonData() {

		String cpmsg = String.format("avatar|%d|%s", m_lUid, szAvatarURL);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ����
class SUBCMD_S_Chat extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	int m_wUserChairID;// �����λ��
	String szContent;

	String getJsonData() {

		String cpmsg = String.format("chat|%d|%d|%s", m_lUid, m_wUserChairID, szContent);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ����
class SUBCMD_S_Voice extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	int m_wUserChairID;// �����λ��
	int seconds;
	String szVoiceURL;

	String getJsonData() {

		String cpmsg = String.format("voice|%d|%d|%d|%s", m_lUid, m_wUserChairID, seconds, szVoiceURL);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ����
class SUBCMD_S_SongLi extends IJsonExport {
	int m_srcUid;// �ĸ����ID���
	int m_dstUid;// �����λ ��
	int m_iLiWu;
	int m_srcCoin;// ����������¶���Ǯ
	int m_dstCoin;// ����������¶���Ǯ

	String getJsonData() {

		String cpmsg = String.format("use|%d|%d|%d|%d|%d", m_srcUid, m_dstUid, m_iLiWu, m_srcCoin, m_dstCoin);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SSeatInfo {
	int m_lUid;// UID
	int m_lTotalCoin;// COIN
	String m_NickName = "";// NICKNAME
	long m_lBetCoin;//
	int m_cbGender;//
	long m_iAvatar;//
	int m_cbUserStatus;// �û�״̬
	int m_iVipLevel;// VIP LEVEL
	int m_iTitle;// �ƺ�
	int m_isLookon;// �Ƿ����
	String szIP = "";
	public int m_iBetCoin;
	int m_iSeatId;// ��λ��ID
	int m_iTotalCoin;// COIN

	int is_offline = 1;

	public String toString() {
		String cpmsg = String.format("%d#%d#%d#%s#%d#%d#%d#%d#%d#%d#%d#%s#%d", m_lUid, m_iSeatId, m_iTotalCoin,
				m_NickName, m_iBetCoin, m_cbGender, m_iAvatar, m_cbUserStatus, m_iVipLevel, m_iTitle, m_isLookon, szIP,
				is_offline);
		return cpmsg;
	}
};

class SUBCMD_S_Table extends IJsonExport { // ͬ�����������Ϣ
	int m_dwTableID;// ����ID
	long m_lCellScore;
	int m_bTableStarted;// ֻҪ��ʼ��
	long m_byRound;//
	long m_byMaxRound;//
	int m_bGameStarted;// ��Ϸ��ʼ
	int m_cntLookon;// ��������

	SSeatInfo m_seatInfo[] = new SSeatInfo[4];
	public int m_byYuPai;
	{
		for (int i = 0; i < m_seatInfo.length; i++) {
			m_seatInfo[i] = new SSeatInfo();
		}
		m_dwTableID = 0;
		m_lCellScore = 1L;
		m_bTableStarted = 1;// ֻҪ��ʼ��
		m_byRound = 1L;//
		m_byMaxRound = 8L;//
		m_bGameStarted = 0;// ��Ϸ��ʼ
		m_cntLookon = 0;// ��������
	}

	String getJsonData() {

		String cpmsg = String.format("table|%d|%d|%d|%d|%d|%d|%d|%s|%s|%s|%s", m_dwTableID, m_bTableStarted, m_byYuPai,
				m_byRound, m_byMaxRound, m_bGameStarted, m_cntLookon, m_seatInfo[0].toString(),
				m_seatInfo[1].toString(), m_seatInfo[2].toString(), m_seatInfo[3].toString());
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// �û�����
class SUBCMD_S_TableBegin extends IJsonExport {
	String strParam;
	int byZhuang;
	long byRound;//
	long byMaxRound;
	int byYuPai;//
	int byCurrentUser;
	int lScore[] = new int[4];
	int lRoundScore[] = new int[4];
	int byLastOutMj;
	int byGuiPai[] = new int[2];

	String getJsonData() {
		String strScore = sprintf_INT32(lScore, 4);
		String strRoundScore = sprintf_INT32(lRoundScore, 4);
		String strGuiPai = sprintf_INT32(byGuiPai, 2);
		String cpmsg = String.format("table_begin|%s|%d|%d|%d|%d|%d|%s|%s|%d|%s", strParam, byZhuang, byRound,
				byMaxRound, byYuPai, byCurrentUser, strScore, strRoundScore, byLastOutMj, strGuiPai);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// �û�����
class SUBCMD_S_TableSide extends IJsonExport {
	int bySeatID;
	int byTing;
	int Maj[] = new int[Constants.HAND_MJ_MAX];
	int Hua[] = new int[8];
	HU hu = new HU();
	int outMj[] = new int[20];
	int byRight[] = new int[6];// ����������Ȩ��
	int fangzi_end;
	int fangzi;
	int fangjiang;
	int lastout_mj;
	int lastout_seat;

	String getJsonData() {

		String strMaj = sprintf_BYTE(Maj, Constants.HAND_MJ_MAX);
		String strHua = sprintf_BYTE(Hua, 8);

		String szHu = String.format("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", hu.jiangMj,
				hu.block[0].style, hu.block[0].first, hu.block[0].count, hu.block[1].style, hu.block[1].first,
				hu.block[1].count, hu.block[2].style, hu.block[2].first, hu.block[2].count, hu.block[3].style,
				hu.block[3].first, hu.block[3].count, hu.block[4].style, hu.block[4].first, hu.block[4].count,
				hu.block[5].style, hu.block[5].first, hu.block[5].count, hu.block[6].style, hu.block[6].first,
				hu.block[6].count);
		String strOutMj = sprintf_BYTE(outMj, 20);
		String strOpRight = sprintf_BYTE(byRight, 6);
		String cpmsg = String.format("table_side|%d|%d|%s|%s|%s|%s|%s|%d|%d|%d|%d|%d", bySeatID, byTing, strMaj, strHua,
				szHu, strOutMj, strOpRight, fangzi_end, fangzi, fangjiang, lastout_mj, lastout_seat);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// �û�����
class SUBCMD_S_TableEnd extends IJsonExport {
	int cbSceneStatus;

	String getJsonData() {

		String cpmsg = String.format("table_end|%d", cbSceneStatus);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// �û�����
class SUBCMD_S_YuPai extends IJsonExport {
	int byYuPai;
	int byCurrentUser;

	String getJsonData() {

		String cpmsg = String.format("yupai|%d|%d", byYuPai, byCurrentUser);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};


//���ַ���
class SUBCMD_S_FaPai_1 extends IJsonExport {
	int byRound;
	int byZhuang;
	int byLianZhuang;
	int byMaxRound;
	int byMj[] = new int[Constants.HAND_MJ_MAX];
	int byHuaPai[][] = new int[RGCPTable.PLAYERCOUNT][8];
	int fangjiang;
	int maizhuang;

	String getJsonData() {
		String strMj0 = sprintf_INT32(byMj, Constants.HAND_MJ_MAX);

		String huapai_str = "";
		for (int i = 0; i < RGCPTable.PLAYERCOUNT; i++) {
			String huapai = sprintf_INT32(byHuaPai[i], 8);
			if ("".equals(huapai_str)) {
				huapai_str = huapai;
			} else {
				huapai_str += "#" + huapai;
			}
		}
		String cpmsg = String.format("fapai_1|%d|%d|%d|%d|%s|%s|%d|%d", byRound, byZhuang, byLianZhuang, byMaxRound, strMj0,
				huapai_str, fangjiang, maizhuang);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class SUBCMD_S_MAIZHUANG_Score extends IJsonExport{
	int[] maizhuang_score;
	String getJsonData(){
		String maizhuang_scoreStr = sprintf_BYTE(maizhuang_score, 3);
		String cpmsg = String.format("maizhuang_score|%s", maizhuang_scoreStr);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString(); 
	}
	
}

// ���ַ���
class SUBCMD_S_FaPai_2 extends IJsonExport {
	int byRound;
	int byZhuang;
	int byLianZhuang;
	int byMaxRound;
	int byMj[] = new int[Constants.HAND_MJ_MAX];
	int byHuaPai[][] = new int[RGCPTable.PLAYERCOUNT][8];
	int fangjiang;

	String getJsonData() {
		String strMj0 = sprintf_INT32(byMj, Constants.HAND_MJ_MAX);

		String huapai_str = "";
		for (int i = 0; i < RGCPTable.PLAYERCOUNT; i++) {
			String huapai = sprintf_INT32(byHuaPai[i], 8);
			if ("".equals(huapai_str)) {
				huapai_str = huapai;
			} else {
				huapai_str += "#" + huapai;
			}
		}
		String cpmsg = String.format("fapai_2|%d|%d|%d|%d|%s|%s|%d", byRound, byZhuang, byLianZhuang, byMaxRound, strMj0,
				huapai_str, fangjiang);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

//���ַ���
class SUBCMD_S_FaPai extends IJsonExport {
	int byRound;
	int byZhuang;
	int byLianZhuang;
	int byMaxRound;
	int byMj[] = new int[Constants.HAND_MJ_MAX];
	int byHuaPai[][] = new int[RGCPTable.PLAYERCOUNT][8];
	int fangjiang;

	String getJsonData() {
		String strMj0 = sprintf_INT32(byMj, Constants.HAND_MJ_MAX);

		String huapai_str = "";
		for (int i = 0; i < RGCPTable.PLAYERCOUNT; i++) {
			String huapai = sprintf_INT32(byHuaPai[i], 8);
			if ("".equals(huapai_str)) {
				huapai_str = huapai;
			} else {
				huapai_str += "#" + huapai;
			}
		}
		String cpmsg = String.format("fapai|%d|%d|%d|%d|%s|%s|%d", byRound, byZhuang, byLianZhuang, byMaxRound, strMj0,
				huapai_str, fangjiang);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

// ��ʾ����
class SUBCMD_S_fangzi extends IJsonExport {
	int bySeatID; // ��ǰ���
	int nGang; // �Ƿ���Ը�

	String getJsonData() {
		String cpmsg = String.format("fangzi|%d|%d", bySeatID, nGang);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ��һȦ����
class SUBCMD_S_First_BUHUA extends IJsonExport {
	int bySeatID; // ��ǰ���
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int hua[] = new int[8];

	String getJsonData() {
		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String strHua = sprintf_BYTE(hua, 8);
		String cpmsg = String.format("first_buhua|%d|%s|%s", bySeatID, strHandMj, strHua);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_longCL extends IJsonExport {
	int byActionUser; // �������
	int byOutMjUser; // �������
	int byMj; // ����
	BLOCK block = new BLOCK(); // ���ƿ�����
	int gangType;// ��������,1-��,2-��,4-�� 5-��
	int byBuMj; // ������ܲ���
	int bTing; // �Ƿ�������
	int bHu[] = new int[4]; // ���ܺ�
	int bZiMoGang; // �Ƿ�������
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int bQiangHu;

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("fangzi_gangpai|%d|%d|%d|%d,%d|%d|%d|%d|%d,%d,%d,%d|%d|%s|%d|%d", byActionUser,
				byOutMjUser, byMj, block.style, block.first, gangType, byBuMj, bTing, bHu[0], bHu[1], bHu[2], bHu[3],
				bZiMoGang, strHandMj, bQiangHu, block.count);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ���Ӻ�ׯ�ҵ�һ�γ���
class SUBCMD_S_First_ChuPai extends IJsonExport {
	int bySeatID; // ��ǰ���
	int nHu; // �Ƿ��ܺ���
	int nGang; // �Ƿ�������

	String getJsonData() {
		String cpmsg = String.format("first_chupai|%d|%d|%d", bySeatID, nGang, nHu);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����
class SUBCMD_S_MoPai extends IJsonExport {
	int reason; // ��ͨ���ƣ����߸��Ͽ���
	int byMoPai; // ����
	int bySeatID; // ��ǰ���
	int bTing; // �Ƿ�������
	int nHu; // �Ƿ��ܺ���
	int nGang; // �Ƿ�������
	int nQiaoXiangHu;
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	String getJsonData() {
		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("mopai|%d|%d|%d|0,0,%d,%d,%d,0,%d|%s", reason, bySeatID, byMoPai, nGang, bTing,
				nHu, nQiaoXiangHu, strHandMj);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����
class SUBCMD_S_FanPai extends IJsonExport {
	int fanPai1; // ����1

	String getJsonData() {
		String cpmsg = String.format("fangpai|%d", fanPai1);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����
class SUBCMD_S_ChuPai extends IJsonExport {
	int byActionUser; // �������
	int byOutMj; // �������
	int bChi; // �ܷ��
	int bPeng; // �ܷ���
	int bGang; // �ܷ��
	int bHu; // �ܷ��
	int byTingPos; // ����POS
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	// Ȩ��,5-��,3-��,2-��,1-��
	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);

		String cpmsg = String.format("chupai|%d|%d|%d,%d,%d,0,%d|%d|%s", byActionUser, byOutMj, bChi, bPeng, bGang, bHu,
				byTingPos, strHandMj);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����
class SUBCMD_S_BuHua extends IJsonExport {
	int bySeatID;// ��λ��
	int byHua; // ����

	String getJsonData() {
		String cpmsg = String.format("buhua|%d|%d", bySeatID, byHua);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����:
class SUBCMD_S_Chi extends IJsonExport {
	int byActionUser; // �������
	int byOutMjUser; // �������
	int byMj; // ����
	BLOCK block = new BLOCK(); // ���ƿ�
	int nChiType; // ��������,0-��,1-@@*, 2-@*@, 4-*@@
	int byTingRight; // ���Ƶ�Ȩ��
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("chipai|%d|%d|%d|%d,%d|%d|%d|%s", byActionUser, byOutMjUser, byMj, block.style,
				block.first, nChiType, byTingRight, strHandMj);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����ѡ��
class SUBCMD_S_ChiMode extends IJsonExport {
	int nChiType;// ��������
};

// ����
class SUBCMD_S_Peng extends IJsonExport {
	int byActionUser; // �������
	int byOutMjUser;// �������
	int byMj; // ����
	BLOCK block = new BLOCK(); // ���ƿ�����
	int byTingRight; // ���Ƶ�Ȩ��
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("pengpai|%d|%d|%d|%d,%d|%d|%d|%s", byActionUser, byOutMjUser, byMj, block.style,
				block.first, 0, byTingRight, strHandMj);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_Ting extends IJsonExport {
	int byActionUser;

	String getJsonData() {

		String cpmsg = String.format("ting|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_KeHuPai extends IJsonExport {
	int byKeHuPai[] = new int[Constants.HAND_MJ_MAX];

	String getJsonData() {
		String strKeHuPai = sprintf_BYTE(byKeHuPai, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("kehupai|%s", strKeHuPai);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����ѡ��
class SUBCMD_S_GangMode extends IJsonExport {
	int byMjGang[] = new int[4]; // �ɸܵ���
	int nGangMode;// ��������
};

// ����
class SUBCMD_S_Fangzi_Gang extends IJsonExport {
	int byActionUser; // �������
	int byOutMjUser; // �������
	int byMj; // ����
	BLOCK block = new BLOCK(); // ���ƿ�����
	int gangType;// ��������,1-��,2-��,4-��
	int byBuMj; // ������ܲ���
	int bTing; // �Ƿ�������
	int bHu[] = new int[4]; // ���ܺ�
	int bZiMoGang; // �Ƿ�������
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int bQiangHu;

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("fangzi_gangpai|%d|%d|%d|%d,%d|%d|%d|%d|%d,%d,%d,%d|%d|%s|%d", byActionUser,
				byOutMjUser, byMj, block.style, block.first, gangType, byBuMj, bTing, bHu[0], bHu[1], bHu[2], bHu[3],
				bZiMoGang, strHandMj, bQiangHu);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

// ����
class SUBCMD_S_Gang extends IJsonExport {
	int byActionUser; // �������
	int byOutMjUser; // �������
	int byMj; // ����
	BLOCK block = new BLOCK(); // ���ƿ�����
	int gangType;// ��������,1-��,2-��,4-��
	int byBuMj; // ������ܲ���
	int bTing; // �Ƿ�������
	int bHu[] = new int[4]; // ���ܺ�
	int bZiMoGang; // �Ƿ�������
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int bQiangHu;

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("gangpai|%d|%d|%d|%d,%d|%d|%d|%d|%d,%d,%d,%d|%d|%s|%d", byActionUser, byOutMjUser,
				byMj, block.style, block.first, gangType, byBuMj, bTing, bHu[0], bHu[1], bHu[2], bHu[3], bZiMoGang,
				strHandMj, bQiangHu);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_HU extends IJsonExport {
	int byWinner; // Ӯ��
	int byFangQiang; // ��û�з�ǹ����
	int byHuMj;
	int winScore[] = new int[4];
	int resultScore[] = new int[4];

	String getJsonData() {

		String strWinScore = sprintf_INT32(winScore, 4);
		String strResultScore = sprintf_INT32(resultScore, 4);
		String cpmsg = String.format("hupai|%d|%d|%d|%s|%s", byWinner, byFangQiang, byHuMj, strWinScore,
				strResultScore);
		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_MoMa extends IJsonExport {
	int vecMaPai[] = new int[6];

	String getJsonData() {
		String strMaPai = sprintf_INT32(vecMaPai, 6);

		String cpmsg = String.format("moma|%s", strMaPai);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		return json.toString();
	}
};

class tagJieSuan {
	int lRoundHushu;
	int lRoundScore;
	int strHuType;
	int huaCount;
	int resultScore;
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	HU hu = new HU();
	int zimo_fangpao;
	String lRoundHuDesc;

	public String toString() {
		String szHu = String.format("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", hu.jiangMj,
				hu.block[0].style, hu.block[0].first, hu.block[0].count, hu.block[1].style, hu.block[1].first,
				hu.block[1].count, hu.block[2].style, hu.block[2].first, hu.block[2].count, hu.block[3].style,
				hu.block[3].first, hu.block[3].count, hu.block[4].style, hu.block[4].first, hu.block[4].count,
				hu.block[5].style, hu.block[5].first, hu.block[5].count, hu.block[6].style, hu.block[6].first,
				hu.block[6].count);

		String strHandMj = IJsonExport.sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String cpmsg = String.format("%d#%d#%s#%s#%d#%d#%d#%d#%s", lRoundScore, strHuType, strHandMj, szHu, lRoundHushu,
				huaCount, resultScore, zimo_fangpao, lRoundHuDesc);
		return cpmsg;
	}
};

class SUBCMD_S_JIESUAN extends IJsonExport {
	int byRound; //
	int byZhuang; //
	int byLianZhuang;
	tagJieSuan userJieSuan[] = new tagJieSuan[4];
	int bCengBao;
	int vecMaPai[] = new int[6];
	int[] guipai = new int[2];
	int fanJiang;
	int[] maizhuang_score;

	{
		for (int i = 0; i < userJieSuan.length; i++) {
			userJieSuan[i] = new tagJieSuan();
		}
	}

	String getJsonData() {

		String strJieSuan0 = userJieSuan[0].toString();
		String strJieSuan1 = userJieSuan[1].toString();
		String strJieSuan2 = userJieSuan[2].toString();
		String strJieSuan3 = userJieSuan[3].toString();

		String strMaPai = IJsonExport.sprintf_BYTE(vecMaPai, 6);
		String strGuiPai = sprintf_INT32(guipai, 2);
		String maizhuang_scoreStr = sprintf_INT32(maizhuang_score, 3);
		String cpmsg = String.format("jiesuan|%d|%d|%d|%s|%s|%s|%s|%d|%s|%s|%d|%s", byRound, byZhuang, byLianZhuang,
				strJieSuan0, strJieSuan1, strJieSuan2, strJieSuan3, bCengBao, strMaPai, strGuiPai, fanJiang, maizhuang_scoreStr);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);

		String result = "";

		json.put("mjresult", result);
		return json.toString();
	}
};

// ����
class SUBCMD_S_Text extends IJsonExport {
	int m_lUid;// �ĸ����ID���
	int m_wUserChairID;// �����λ��
	String szContent;

	String getJsonData() {
		String cpmsg = String.format("text|%d|%d|%s", m_lUid, m_wUserChairID, szContent);

		JSONObject json = new JSONObject();
		json.put("command", "cpmsg");
		json.put("cpmsg", cpmsg);
		return json.toString();
	}
};

class SUBCMD_S_TryDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String ddzmsg = String.format("try_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "ddzmsg");
		json.put("ddzmsg", ddzmsg);

		return json.toString();
	}
};

class SUBCMD_S_AgreeDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String ddzmsg = String.format("agree_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "ddzmsg");
		json.put("ddzmsg", ddzmsg);

		return json.toString();
	}
};

class SUBCMD_S_RefuseDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String ddzmsg = String.format("refuse_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "ddzmsg");
		json.put("ddzmsg", ddzmsg);

		return json.toString();
	}
};